﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<IPagedList<MensUnoShop.Models.ManagerSimpleMarket>>" %>
<%@ Import Namespace="MvcPaging"%>  
<%@ Import Namespace="MensUnoShop.Helpers" %>
<%@ Import Namespace="MensUnoShop.Areas.Admin.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	MarketList
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" language="javascript">
    function ChangeMarketStatus(mkguid, mktype) {          
        var jsonstring = { "mkguid": mkguid, "mktype": mktype };
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/Admin/Product/ChangeMarketStatus",
            data: jsonstring,
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    alert("修改成功!");
                    if (data.response == "true")
                        $("#btn_" + mkguid).attr('value', '上架中');
                    else if (data.response == "false")
                        $("#btn_" + mkguid).attr('value', '下架中');
                }
                else
                    alert(data.response);
            }
        });
    }
</script>

	    <div id="main-content" class="hastable">
		    <div class="title title-spacing">
			    <h2>賣場列表</h2>
					依下列條件查詢所有賣場資料
		    </div>
            <%using (Html.BeginForm("MarketList", "Product", FormMethod.Post, new { @class = "shBox" }))
            {%>
                <%:Html.DropDownList("FirstLevel", (IEnumerable<SelectListItem>)ViewData["FirstLevelList"])%> - 
                <%:Html.DropDownList("SecondLevel", new List<SelectListItem> { new SelectListItem() { Text = "請先選左方分類", Value = "" } })%>
                <input type="text" name="query" value="" onfocus="this.value='';" />
                <input type="submit" class="submit" value="取得賣場列表" />
                <input type="button" value="新增賣場" onclick="javascript:location.href='Market/0'" />                
          <%} %>

            <ul class="pagination">
            <%= Html.UPager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)%>
            </ul>

            <table cellspacing="0">
            <thead>
				<tr>
					<td style="width:80px;">商品貨號</td>
					<td style="width:300px">賣場標題</td>
                    <td style="width:120px">開賣時間</td>
                    <td style="width:120px">結束時間</td>
                    <td style="width:40px">訂價</td>
                    <td style="width:40px">售價</td>
                    <td style="width:55px">庫存</td>
                    <td style="width:30px">狀態</td>
                    <td></td>
				</tr>
			</thead>
            <%if (Model != null){%>
             <tbody>
            <%foreach (var item in Model)
            {  %>
        	    <tr align="center">
                    <td align="center" style="text-align: center;vertical-align:top"><%:item.SN %></td>
                    <td style="vertical-align:top"><%:item.TITLE %></td>
                    <td align="center" style="text-align: center;vertical-align:top"><%:item.SDATE.ToString("yyyy/MM/dd")%></td>
                    <td align="center" style="text-align: center;vertical-align:top"><%:item.EDATE.ToString("yyyy/MM/dd")%></td>
                    <td align="center" style="text-align: center;vertical-align:top"><%:item.SHOPPRICE%></td>
                    <td align="center" style="text-align: center;vertical-align:top"><%:item.PRICE %></td>
                    <td align="center" style="text-align: center">
                        <%foreach (var mp in item.MSPLIST)
                          { %>
                        <table style="margin:0px;width:auto;">
                            <tr>
                            <td colspan="<%:mp.MSSLIST.Count %>" style="background-color:#CC3366;color:White;padding:5px;width:40px;text-align:center"><%:mp.PNAME %></td>
                            </tr>
                             <tr style="background-color:#E4E4E4">
                            <%foreach (var ms in mp.MSSLIST)
                              { %>
                            <td style="background-color:#E4E4E4;font-weight:bold;padding:5px;text-align:center"><%:ms.SSNAME %></th><%} %>
                            </tr>
                             <tr>
                            <%foreach (var ms in mp.MSSLIST)
                              { %>
                            <td style="padding:5px;text-align:center"><%:ms.SSTOCK %></td><%} %>
                            </tr>
                        </table>
                        <%} %>
                    </td>
                    <td align="center" style="text-align: center;vertical-align:top"><input id="btn_<%:item.MKGUID %>" name="btn_<%:item.MKGUID %>" value="<%if(item.STATUS){%>上架中<%}else{ %>下架中<%} %>" type="button" onclick="ChangeMarketStatus('<%:item.MKGUID %>',<%:(int)item.TYPE %>);" /></td>
                    <td style="vertical-align:top;"><a id="Market" name="Market" href="Market/<%:item.MKGUID %>">賣場明細</a> | 
                        <a id="MarketPicture" name="MarketPicture" href="MarketPictureDetail/<%:item.MKGUID %>">圖說</a> | 
                        <a id="Product" name="Product" href="ProductDetail/<%:item.MKGUID %>">商品列表</a></td>
                </tr>
            <%} %>
            </tbody>
            <%} %>
            </table>

            <ul class="pagination" style="margin-top:-60px;">
            <%= Html.UPager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)%>
            </ul>
            <br/><br/>　
        </div>

<script type="text/javascript">
    $(document).ready(function () {
        <%var temp1 = Session["SL1"]==null?"0": Session["SL1"].ToString();%>
        $("#FirstLevel").attr('value',"<%:temp1 %>");
        $("#FirstLevel").trigger("change");

    });

    $("#FirstLevel").change(GetSubTagList);
    function GetSubTagList() {
        $.getJSON("GetSubTagList/", { pid: $("#FirstLevel").val() }, function (data) {            
            $("#SecondLevel").empty();
            $("#SecondLevel").append('<option value="0">=請選擇=</option>');
            $.each(data, function (i, item) {
                $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#SecondLevel"));
            });
            <%var temp = Session["SL"] as string;if(!string.IsNullOrEmpty(temp)){ %>
            $("#SecondLevel option").each(function(){if($(this).val()=='<%:temp %>'){$("#SecondLevel").attr('value','<%:temp %>');}});
            
        <%} %>

            $("#SecondLevel").trigger("change");
        });
    }
    $("#SecondLevel").change(function () { });
</script>
</asp:Content>